<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Admin_model extends MY_model {
	public function __construct() {
		parent::__construct ( 'admin' );
	}
	/**
	 * 创建数据表
	 */
	public function create() {
		$this->drop ();
		$sql = "CREATE TABLE `admin` (
					  `id` varchar(20) NOT NULL COMMENT '管理员ID',
					  `email` varchar(200) NOT NULL COMMENT 'Email',
					  `password` varchar(255) NOT NULL COMMENT '密码',
					  `createtime` int(10) unsigned NOT NULL COMMENT '创建时间',
					  `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '管理员状态（0：冻结；1：未激活；2：激活）',
					  PRIMARY KEY (`id`,`email`)
					) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='管理员表';";
		$re = $this->db->simple_query ( $sql );
		$this->init ();
		return $re;
	}
	/**
	 * 初始化一条数据
	 */
	public function init($admin = 'admin', $pwd = '', $email = '') {
		$pwd = 'WwhYsqHsK2WIfxgDL/5b3VSjXQWJbdlTfTlsUI1JwASf5ASJyyzKTlINR1proKIZBeq/1I1FTDV7yz383s9I9g==';
		$time = time ();
		$sql = "INSERT INTO `admin` VALUES ('{$admin}', '{$email}', '{$pwd}', '{$time}', '1');";
		$re = $this->db->simple_query ( $sql );
		return $re;
	}
	/**
	 * 删除数据表
	 */
	public function drop() {
		$sql = 'DROP TABLE IF EXISTS `admin`;';
		$re = $this->db->simple_query ( $sql );
		return $re;
	}
}